﻿#region

using System.Security.Cryptography;
using System.Text;

#endregion

namespace DomainModel.Utils
{
    public class Md5HasherImpl : IMd5Hasher
    {
        public string Md5(byte[] bytes)
        {
            StringBuilder sb = new StringBuilder();

            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] hash = md5.ComputeHash(bytes);

            foreach (byte hex in hash)
            {
                sb.Append(hex.ToString("x2"));
            }
            string md5Sum = sb.ToString();

            return md5Sum;
        }

        public string Md5(string str)
        {
            var utf8 = new UTF8Encoding();
            return Md5(utf8.GetBytes(str));
        }
    }
}